function Soldier(color) {
	var hash = Math.floor(Math.random()*1000);
	var dom = "<div id='"+hash+"'style='width:8px;height:32px; position:absolute;top:0px;left:0px;padding:0px;margin:0px'><div class='soldierGraphic'>^</div></div>";
	var sprite = $(dom);
	this.name = color;
	sprite.find(".soldierGraphic").css("background-color",color);
	sprite.css({ "top": 552, "left":1824 } )
	$("#canvas").append(sprite);
	var speed = 0.5;
	var self = this;
	var sightRadius = 500;
	var rotation = 0;
	var sightCone = Math.PI/3;
	var lostimer;
	
	
	var sightDirection = 0.1;
	var drawLos = function() {
		clearInterval(lostimer);
		var x = parseInt(sprite.css("left"),10);
		var y = parseInt(sprite.css("top"),10);
		sightCone+=sightDirection;
		if(Math.abs(sightCone)>Math.PI) {
			sightDirection*=-1;
		}
		losMap.drawSight(x,y,sightCone,sightRadius)
		lostimer = setInterval(drawLos,50);
		
	}
	
	this.moveTo = function(x,y) {
		$(".debugSq").remove();
		sprite.stop();
		var currentX = parseInt(sprite.css("left"),10);
		var currentY = parseInt(sprite.css("top"),10);
		var path = [{"x":x,"y":y}]//collisionMap.pathFind({"x":currentX,"y":currentY},{"x":x,"y":y});
		//path.push({"x":x,"y":y});
		var cnt = 0;
		
		function nextWp() {
			var x = path[0].x;
			var y = path[0].y
			var currentX = parseInt(sprite.css("left"),10);
			var currentY = parseInt(sprite.css("top"),10);
			var lengthOfPath = mathutils.distanceFrom2Points(x,y,currentX,currentY);
			cnt++;
//			collisionMap.createBlock(x,y,cnt,true);
			rotation = Math.tan(currentX-x/currentY-y);
			if(currentX-x<0!=currentY-y<0) {
				rotation+=Math.PI/2
			}
			console.log(rotation,currentX-x<0,currentY-y<0)
			if(currentY-y<0) rotation+=Math.PI/2
			sprite.css("-webkit-transform","rotate("+rotation+"rad)")
			sprite.animate({"top": y, "left":x},lengthOfPath / speed, "swing", function() {
				path.shift();

				if(path.length!=0) {
					nextWp();
				} else {
					drawLos();
				}
			})
		}
		var x = path[0].x;
		var y = path[0].y
		var lengthOfPath = mathutils.distanceFrom2Points(x,y,currentX,currentY);
		rotation = Math.tan(currentX-x/currentY-y);
		if(currentX-x<0!=currentY-y<0) {
			rotation+=Math.PI/2
		}
		console.log(rotation,currentX-x,currentY-y)
		//((currentY-y)<0) rotation+=Math.PI/2
		sprite.css("-webkit-transform","rotate("+rotation+"rad)")
//		collisionMap.createBlock(x,y,cnt,true);
		sprite.animate({"top": y, "left":x},lengthOfPath / speed, "swing", function() {
//			path.shift();
//			if(path.length!=0) {
//				nextWp();
//			} else {
				;
//			}
		})
		drawLos()


	};
	
	sprite.on("mousedown",function(event) {
		selectControl.requestSelect(self);
		event.stopPropagation();
	});
	
	
	this.selected = function() {
		sprite.find(".soldierGraphic").css("border"," 3px solid #00FF21");
		var currentX = parseInt(sprite.css("left"),10);
		var currentY = parseInt(sprite.css("top"),10);
	};
	
	this.deselected = function() {
		sprite.find(".soldierGraphic").css("border"," 0");
	};
};